package com.example.websocketdemo.controller.CIMVUE;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.CallThePolice;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

@RestController
@RequestMapping("/VUEMajorRightProductionRisk")
public class MajorRightProductionRiskController {

    @GetMapping("/remit")
    public JSONArray remit(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("重大危险源", "35");
        jsonObject.put("关键重大部位", "0");
        jsonObject.put("可燃气体", "0");
        jsonObject.put("一般风险", "0");
        jsonObject.put("环境监测", "0");
        return bianli(jsonObject);
    }

    @GetMapping("/video")
    public JSONArray video(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObject1 = new JSONObject();
        JSONObject jsonObject3 = new JSONObject();
        JSONObject jsonObject4 = new JSONObject();
        jsonObject.put("title","视频");
        jsonObject1.put("title","视频");
        jsonObject3.put("title","视频");
        jsonObject4.put("title","视频");
        jsonObject.put("src","https://www.w3schools.com/html/movie.mp4");
        jsonObject1.put("src","https://www.w3schools.com/html/movie.mp4");
        jsonObject3.put("src","https://www.w3schools.com/html/movie.mp4");
        jsonObject4.put("src","https://www.w3schools.com/html/movie.mp4");

        jsonArray.add(jsonObject);
        jsonArray.add(jsonObject1);
        jsonArray.add(jsonObject3);
        jsonArray.add(jsonObject4);
        return jsonArray;
    }

    @GetMapping("/data")
    public JSONArray d(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
//        JSONArray jsonArray = new JSONArray();
//        JSONObject jsonObject = new JSONObject();
//        JSONObject jsonObject1 = new JSONObject();
//        JSONObject jsonObject2 = new JSONObject();
//        jsonObject.put("bitnum", "LYG_5450_PT_01001_PV");
//        jsonObject.put("callpolice", "低报");
//        jsonObject.put("realval", "0.063 ℃");
//        jsonObject.put("prewarningval", "0.1");
//        jsonObject.put("time", "2022-02-23 15:42:00");
//        jsonObject.put("equipment", "5450-TK-001");
//
//        jsonObject1.put("bitnum", "LYG_5450_TT_01002_PV");
//        jsonObject1.put("callpolice", "低报");
//        jsonObject1.put("realval", "19.885 ℃");
//        jsonObject1.put("prewarningval", "20");
//        jsonObject1.put("time", "2022-02-22 05:54:00");
//        jsonObject1.put("equipment", "5450-TK-002");
//
//        jsonObject2.put("bitnum", "LYG_5450_TT_01002_PV");
//        jsonObject2.put("callpolice", "低报");
//        jsonObject2.put("realval", "19.91 ℃");
//        jsonObject2.put("prewarningval", "20");
//        jsonObject2.put("time", "2022-02-22 04:54:00");
//        jsonObject2.put("equipment", "5450-TK-002");
//
//        jsonArray.add(jsonObject);
//        jsonArray.add(jsonObject1);
//        jsonArray.add(jsonObject2);
        CallThePolice callThePolice = new CallThePolice();
        return callThePolice.alarmln();
    }

    private JSONArray bianli(JSONObject jsonObject) {
        JSONArray jsonArray = new JSONArray();
//        JSONObject json = new JSONObject();
        Iterator iter = jsonObject.entrySet().iterator();
        while (iter.hasNext()) {
            JSONObject json = new JSONObject();
            Map.Entry entry = (Map.Entry) iter.next();
            json.put("title", entry.getKey().toString());
            json.put("value", entry.getValue().toString());
            jsonArray.add(json);
        }
        return jsonArray;
    }


}
